package com.qingyun.user.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.qingyun.model.common.dtos.R;
import com.qingyun.model.user.pojos.UserFan;
import com.qingyun.user.mapper.UserFanMapper;
import com.qingyun.user.service.UserFanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import utils.thread.AppThreadLocalUtil;

import java.util.List;


@Service("userFanService")
public class UserFanServiceImpl extends ServiceImpl<UserFanMapper, UserFan> implements UserFanService {


    @Override
    public R isFan(Long userId) {
        UserFan one = query().eq("user_id", AppThreadLocalUtil.getUser().getId()).eq("fans_id", userId).one();
        if (ObjectUtil.isEmpty(one))return R.error("对方尚未关注你");
        return R.success("对方关注了你");
    }

    @Override
    public R fanList(Long userId) {
        List<UserFan> userFans = query().eq("user_id", userId).list();
        if (userFans.isEmpty())return R.success("没有小伙伴关注你哦~");
        return R.success(userFans);
    }

    @Override
    public Integer fansCount(Long userId) {

        return query().eq("user_id", userId).count();
    }
}